package com.abner.design.patterns.state;

/**
 * 环境角色, 用于维护 State 实例,这个实例定义当前状态
 * @author abner
 */
public class RaffleActivity {

    /**
     * 当前活动状态
     */
    State state = null;

    /**
     * 奖品数量
     */
    int count = 0;

    /**
     * 声明四种抽奖状态
     */
    State noRafflleState = new NoRaffleState(this);
    State canRaffleState = new CanRaffleState(this);
    State dispenseState =   new DispenseState(this);
    State dispensOutState = new DispenseOutState(this);

    /**
     * 初始化当前的状态为 noRafflleState（即不能抽奖的状态）
     * 初始化奖品的数量
     * @param count
     */
    public RaffleActivity( int count) {
        this.state = getNoRafflleState();
        this.count = count;
    }

    /**
     * 扣积分
     */
    public void debuctMoney(){
        state.deductMoney();
    }

    /**
     * 抽奖
      */
    public void raffle(){
        if(state.raffle()){
            state.dispensePrize();
        }
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public int getCount() {
    	int curCount = count; 
    	count--;
        return curCount;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public State getNoRafflleState() {
        return noRafflleState;
    }

    public void setNoRafflleState(State noRafflleState) {
        this.noRafflleState = noRafflleState;
    }

    public State getCanRaffleState() {
        return canRaffleState;
    }

    public void setCanRaffleState(State canRaffleState) {
        this.canRaffleState = canRaffleState;
    }

    public State getDispenseState() {
        return dispenseState;
    }

    public void setDispenseState(State dispenseState) {
        this.dispenseState = dispenseState;
    }

    public State getDispensOutState() {
        return dispensOutState;
    }

    public void setDispensOutState(State dispensOutState) {
        this.dispensOutState = dispensOutState;
    }
}
